﻿#ifndef __HELLOWORLD_SCENE_H__
#define __HELLOWORLD_SCENE_H__

#include "cocos2d.h"
#include "cocostudio/CocoStudio.h"
#include "ui/CocosGUI.h"

#include "MyPublicMacro.h"

using namespace cocos2d;
USING_NS_CC;

#define  THREAD_MAX_LOOP  1000			// 线程内循环次数，用于测试
#define  THREAD_SLEEP_IN_LOOP  50			// 线程内在每次循环中的睡眠时间，ms，用于测试

class HelloWorld : public cocos2d::Layer
{
public:
    // there's no 'id' in cpp, so we recommend returning the class instance pointer
    static cocos2d::Scene* createScene();

	HelloWorld::~HelloWorld();

    // Here's a difference. Method 'init' in cocos2d-x returns bool, instead of returning 'id' in cocos2d-iphone
    virtual bool init();

    // implement the "static create()" method manually
    CREATE_FUNC(HelloWorld);

	//virtual void onExit();

	// 进入场景后，要初始化内容
	virtual void onEnterTransitionDidFinish();

	// 离开场景前，要释放内容
	virtual void onExitTransitionDidStart();

	void OnTimer01(float dt);

	// 事件桥梁定时器的回调函数
	void OnEventBridge(float dt);

	// 发送自定义消息
	void sendCustomEvent();

	void OnBt1(Ref * pSender, ui::Widget::TouchEventType type);

	// // 向数据仓库写入数据
	void OnBt2(Ref * pSender, ui::Widget::TouchEventType type);

	// 从数据仓库中读取数据
	void OnBt3(Ref * pSender, ui::Widget::TouchEventType type);

	// 向服务端发送一条消息
	void OnBt4(Ref * pSender, ui::Widget::TouchEventType type);

	// 向服务端发送一批信息
	void OnBt5(Ref * pSender, ui::Widget::TouchEventType type);

	// 用线程压力测试数据仓库
	void OnBt6(Ref * pSender, ui::Widget::TouchEventType type);

	void OnBt7(Ref * pSender, ui::Widget::TouchEventType type);
	void OnBt8(Ref * pSender, ui::Widget::TouchEventType type);
	void OnBt9(Ref * pSender, ui::Widget::TouchEventType type);

	void threadWriteToRepository();

	// 线程，向数据仓库写入数据，用于压力测试
	void threadReadFromRepository();

public:
	// 注册同步事件监听器
	void addCustomEventListener();

	void OnMyEventCustom01(EventCustom* event);
	void OnMyEventCustom02(EventCustom* event);

public:
	Node*  m_pRootNode=nullptr; 

	std::thread		_writeToRepositoryThread;
	std::thread		_readFromRepositoryThread;
};

#endif // __HELLOWORLD_SCENE_H__
